package com.axjy.web;

import com.axjy.pojo.Systemconfig;
import com.axjy.service.SystemconfigService;
import com.axjy.service.vo.Pager;
import com.axjy.util.Log;
import org.omg.CORBA.INTERNAL;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 00 on 2018/1/30.
 */
@RestController
@RequestMapping("/sys/config")
public class SystemconfigHandler {

    @Resource
    private SystemconfigService config;

    @GetMapping("/show")
    public Pager configshow(@RequestParam(defaultValue = "0")Integer offset, @RequestParam(defaultValue = "4")Integer limit, Integer peiStatus){
        Pager p=config.peizhishow(offset,limit,peiStatus);
        return p;
    }

    @GetMapping("/search1")
    public List<Systemconfig> search1(){return config.search1();}

    @GetMapping("/search2")
    public List<Systemconfig> search2(){ return config.search2();}


    @PostMapping(value = "/add")
    public String add(Systemconfig systemconfig){
        String isOk=null;
        try{
            systemconfig.setConfigValueId(config.maxid()+1);
            config.add(systemconfig);
            isOk="新增成功";
        }catch (Exception ex){
            isOk="新增失败";
            Log.logger.error(isOk,ex);
        }
        return isOk;
    }

    @PostMapping("/update")
    public String update(Systemconfig sy){
        String isOk=null;
        try{
            System.out.println(sy.getId());
            config.update(sy);
            isOk="修改成功";
        }catch (Exception ex){
            isOk="修改失败";
            Log.logger.error(isOk,ex);
        }
        return isOk;
    }

    @PostMapping("/delete")
    public String del(String[] ids){
        String isOk="1";
        Map<String,Object> map=new HashMap<>();
        map.put("ids",ids);
        try{
            config.del(map);
        }catch (Exception ex){
            isOk="0";
            Log.logger.error(isOk,ex);
        }
        return isOk;
    }

    @PostMapping("/ztupdate")
    public String ztisstart(Integer id,Integer isStart){
        String isOk=null;
        try{
            config.ztisstart(id, isStart);
            isOk="修改成功！";
        }catch (Exception ex){
            isOk="修改失败！";
            Log.logger.error(isOk,ex);
        }
        return isOk;
    }


}
